
//
// 101119 - AH - Created.
// 101120 - AH - Button to delete resource.
// 101127a- AH - CreateResourceDialog constructor used now accepts
//               SoekratEngine.
// 101127b- AH - Generate HistoricalEvent when resource edited.
// 101127c- AH - Generate HistoricalEvent when resource deleted.
// 101217 - AH - Resources are now of type Resource, not AttributeObject 
//               directly.
// 110615 - AH - (Bien *) Missing java doc added.
// 110808 - AH - (Bybanen *) Deprecated.
//

package org.soekrat.gui.swing.resource;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.soekrat.engine.mine.Resource;

/**
 * <p>
 *   {@link JInternalFrame} used to show a
 *   {@link Resource} on the
 *   {@link ResourceWall}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
@Deprecated
@SuppressWarnings("serial")
public final class WallResourceFrame extends JInternalFrame 
{
  private final ResourcePanel m_rp=new ResourcePanel();
  
  private final ResourceWall m_wall;
  
  private CreateResourceDialog m_crd=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param wall {@link ResourceWall} {@code this} is on.
   */
  public WallResourceFrame(ResourceWall wall) 
  {
    if (wall==null)
    {
      throw new NullPointerException("wall");
    }
    
    m_wall=wall;
    
    setClosable(false);
    setIconifiable(true);
    setMaximizable(true);
    setResizable(true);
    
    Container c=getContentPane();
    c.setLayout(new BorderLayout());
    c.add(m_rp, BorderLayout.CENTER);
    
    JPanel buttons=new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttons.add
    (
      new JButton
      (
        new AbstractAction("Edit")
        {
          public void actionPerformed(ActionEvent e) 
          {
            Resource resource=m_rp.getResource();
            if (m_crd==null) m_crd=new CreateResourceDialog(m_wall.getEngine());
            Resource newResource=m_crd.showDialog("Edit", resource);
            if (newResource!=null)
            {
              m_wall.removeResource(resource);
              m_wall.addResource(newResource);
            }
          }
        }
      )
    );
    buttons.add
    (
      new JButton
      (
        new AbstractAction("Delete")
        {
          public void actionPerformed(ActionEvent e) 
          {
            if (JOptionPane.showConfirmDialog(WallResourceFrame.this, 
              "Sure You Want To Delete Resource", "Confirm Delete", 
              JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
            {
              Resource resource=m_rp.getResource();
              m_wall.removeResource(resource);
              dispose();
              m_wall.remove(WallResourceFrame.this);
            }     
          }
        }
      )
    );
    
    c.add(buttons, BorderLayout.SOUTH);
    
    pack();
    setSize(250, 200);
  }
  
  /**
   * <p>
   *   Sets resource to view.
   * </p>
   * @param resource {@link Resource}.
   */
  public void setResource(Resource resource)
  {
    m_rp.setResource(resource);
    pack();
  }
  
}
